package com.enation.app.shop.front.policyInsurance.service.impl;

import com.enation.app.shop.front.api.inpolicy.entity.InPolicy;
import com.enation.app.shop.front.policyInsurance.service.InsuranceProtOrdMapper;
import com.enation.framework.database.IDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class InPolicyProtOrdManagerService implements InsuranceProtOrdMapper {
    @Autowired
    private IDaoSupport iDaoSupport;

    @Override
    public InPolicy getInPolicyDeatil(int inPolicy_id) {
        String sql = "select * from rbt_inpolicy r where r.warranty_id=?";
        InPolicy inPolicy=iDaoSupport.queryForList(sql,InPolicy.class,inPolicy_id).get(0);
        if(inPolicy!=null){
            return inPolicy;
        }
        return null;
    }

    @Override
    public List<InPolicy> getAllInPolicyOrderInfo() {
        String sql = "select * from rbt_inpolicy r where r.is_policy=1 ORDER BY r.begin_time desc";
        return iDaoSupport.queryForList(sql,InPolicy.class);
    }

    @Override
    public List<InPolicy> getUnExplorInPolicyOrderInfo() {
        String sql = "select * from rbt_inpolicy r where r.is_policy=1 and r.`status`=0 ORDER BY r.begin_time desc";
        return iDaoSupport.queryForList(sql,InPolicy.class);
    }

    @Override
    public List<InPolicy> getCheckInPolicyOrderInfo() {
        String sql = "select * from rbt_inpolicy r where r.is_policy=1 and r.status=1 ORDER BY r.begin_time desc";
        return iDaoSupport.queryForList(sql,InPolicy.class);
    }

    @Override
    public List<InPolicy> getOverInPolicyOrder() {
        String sql="select * from rbt_inpolicy r where r.is_policy=1 and r.status=6 ORDER BY r.begin_time desc";
        return iDaoSupport.queryForList(sql,InPolicy.class);
    }
    @Override
    public List<InPolicy> getHistoryOrder(Integer userid){
        String sql="select r.warranty_number from rbt_inpolicy r where r.is_policy=1 and r.status=6 and r.user_id=? ORDER BY r.begin_time desc";
        return iDaoSupport.queryForList(sql,InPolicy.class,userid);
    }

    //获取所有信用额度支付的保险订单
    @Override
    public List<InPolicy> getAllCreaditOrder(Integer page,Integer limit,String inPolicy_number) {
        String sql = "SELECT * from rbt_inpolicy s where s.is_policy=1 and s.status=8 and s.payment_type=5";
//        if(inPolicy_number!=null){
//            sql +=" and s.warranty_number LIKE '%"+inPolicy_number+"%'";
//        }
            sql +=" limit ?,?";
        List<InPolicy> inPolicyList=iDaoSupport.queryForList(sql,InPolicy.class,page,limit);
        if(inPolicyList.size()>0){
            return inPolicyList;
        }else {
            return null;
        }
    }
}
